﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Power.DataEntity;
using TjZheng.Framework;
using TjZheng.Redis;
using TjZheng.Power.Business;
using TjZheng.Power.RedisEntity;

namespace TjZheng.CMS.Process
{
    public static class PowerRedisExtension
    {
        public static List<PowerInfo> CreatePowerInfoList(this List<long> powerIdList)
        {
            if (powerIdList.IsNull())
            {
                return null;
            }
            return RedisHelper.GetByIds<PowerInfo>(powerIdList, PowerVariable.ProviderName, PowerVariable.Db).ToList();
        }
        public static List<GroupInfo> CreateGroupInfoList(this List<long> groupIdList)
        {
            if (groupIdList.IsNull())
            {
                return null;
            }
            return RedisHelper.GetByIds<GroupInfo>(groupIdList, PowerVariable.ProviderName, PowerVariable.Db).ToList();
        }
        public static List<GroupInfo> CreateGroupInfoList(this long userId)
        {
            if (userId <= 0)
            {
                return null;
            }
            UserRole objUserRole = RedisHelper.GetById<UserRole>(userId, PowerVariable.ProviderName, PowerVariable.Db);
            if (objUserRole == null || objUserRole.GroupIds.IsNull())
            {
                return null;
            }
            return objUserRole.GroupIds.CreateGroupInfoList();
        }
    }
}
